var bip39 = require('bip39')
var hdkey = require('ethereumjs-wallet/hdkey')
var util = require('ethereumjs-util')
var Tx = require('ethereumjs-tx');
var keythereum = require("keythereum");
var Web3 = require('web3');
if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  // set the provider you want from Web3.providers
  web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
var keythereum = require("keythereum");

var privateKey = "07480b3334f1cde7fc8c067304d474c0cf2dab6027befee4c28585be196a59a3"

//console.log(Buffer.from(privateKey,'hex'))


publicKey = util.secp256k1.publicKeyCreate(Buffer.from(privateKey,'hex'), false).slice(1);
console.log("publicKey==========")
console.log(publicKey.toString('hex'))
console.log("Address==========")
console.log(util.privateToAddress(Buffer.from(privateKey,'hex')).toString('hex') )

var message = "deadbeaf"      //不能带0x
const msgHash  = util.hashPersonalMessage(Buffer.from(message,'hex'))
console.log("msgHash==========")
console.log(msgHash.toString('hex'))
//ca1ad489ab60ea581e6c119cc39d94ddbfc5faa0e178a23ca66202c8c2a72277
//5f35dce98ba4fba25530a026ed80b2cecdaa31091ba4958b99b52ea1d068adad

var signAddress = util.ecsign(msgHash,Buffer.from(privateKey,'hex'))
console.log("sign==========")
console.log(signAddress.r.toString('hex')+signAddress.s.toString('hex'))

//0x9eda0abaa6ae0c7647a1a449f3903a53387b6f5375eb927775605601d201cc8577855a1f3be83f92d27e61e4989e9fdea0af4f16bd5f497065eee0b026ac1a0f1b
//fddf78da017d8cac8a825536e8a903d9c8fc8b51a4245e08414e3b905de900029f76f869f9e001111edfe82e77f10d0d6e52b858f1c6e789ae41d3e348bf08cc
//7f7d8e7f7045636a1c954dd19d83b0f045141e31159de1a9a4d85b9c86882abd1d7517f34a1c15ee
//4da1faf9a898a97667a4567647dc729b4adcc052be8f0ed4
//27


//0xf1d142e556126dd6e8b4be77b59760c9776ce1d8150123a707cbcaf36758cc0b
//0x69744dd69c5e90af827516190c96ed9223d75d006538f8e746ab7d251ca806c8